package com.dotto.atos.ui;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.TextView;

import com.dotto.atos.R;
import com.dotto.atos.models.Announcement;

public class AnnouncementListAdapter extends ArrayAdapter<Announcement> {
	private final Context context;
	private final Announcement[] values;

	public AnnouncementListAdapter(Context context, Announcement[] values) {
		super(context, R.layout.announcement_list_item, values);
		this.context = context;
		this.values = values;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		LayoutInflater inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

		View rowView = inflater.inflate(R.layout.announcement_list_item,
				parent, false);

		Announcement ref = values[position];

		TextView subject = (TextView) rowView
				.findViewById(R.id.label_ref_subject);
		subject.setText(ref.subject);
		TextView from = (TextView) rowView.findViewById(R.id.label_ref_from);
		from.setText(ref.from);
		TextView to = (TextView) rowView.findViewById(R.id.label_ref_to);
		to.setText(ref.to);
		EditText message = (EditText) rowView.findViewById(R.id.text_ref_desc);
		message.setText(ref.getMessage());

		return rowView;
	}
}
